package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.RequestCityHandler;
import com.cungmua.app.model.request.CityRequest;
import com.cungmua.app.model.response.CityResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/16/14.
 */
public class RequestCityTask extends AuthenticatedTask<CityRequest, Void, CityResponse> {
    private final Context context;
    private RequestCityHandler handler;

    public RequestCityTask(Context context, RequestCityHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected CityResponse doInBackground() throws RetrofitError {
        CityRequest request = params[0];

        return service.getListCity(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(CityResponse cityResponse) {
        handler.onListCity(cityResponse);
    }
}
